package gui._3监听器;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TextListener {
    public static void main(String[] args) {
        TextFrame textFrame = new TextFrame("文本测试窗口");
        //新建文本框
        TextField textField = new TextField();
        textFrame.add(textField,BorderLayout.CENTER);
        textFrame.setVisible(true);
        ActionListener actionListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println(e.getActionCommand());
            }
        };
        textField.addActionListener(actionListener);
    }
    //将窗口类封装
    static class TextFrame extends Frame{
        public TextFrame(String title){
            super(title);
            this.setBounds(200,200,500,400);
        }
    }
}

